package leetCode.solution;

public class Trie {
	public static void main(String[] args) {
		String[] arr = new String[] { "as", "asd", "asdf", "z", "zx", "zxc", "az" };
		TrieTree(arr);
	}

	public static void TrieTree(String[] arr) {
		Node root = new Node();
		for (String s : arr) {
			char[] chs = s.toCharArray();
			Node node = root;
			int index = 0;
			for (int i = 0; i < chs.length; i++) {
				index = chs[i] - 'a';
				if (node.nexts[index] == null) {
					node.nexts[index] = new Node();
				}
				node = node.nexts[index];
			}
			node.end = true;
		}
	}

	public static class Node {
		public boolean end;
		public Node[] nexts;

		public Node() {
			end = false;
			nexts = new Node[26];
		}
	}

}
